﻿
//生成[Posts]Repository代码
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FineAdmin.IRepository;
using FineAdmin.Model;
using Dapper;

namespace FineAdmin.Repository
{
    public class PostsRepository : BaseRepository<PostsModel>, IPostsRepository
    {
        public int AddClicks(int id)
        {
            using (var conn = SqlHelper.SqlConnection())
            {
                string sql = @"UPDATE Posts Set Clicks=Clicks+1 WHERE Id = "+ id;
                return conn.ExecuteScalar<int>(sql);
            }
        }

        public int AddLikes(int id)
        {
            using (var conn = SqlHelper.SqlConnection())
            {
                string sql = @"UPDATE Posts Set Likes=Likes+1 WHERE Id = " + id;
                return conn.ExecuteScalar<int>(sql);
            }
        }

        public int AddTrample(int id)
        {
            using (var conn = SqlHelper.SqlConnection())
            {
                string sql = @"UPDATE Posts Set Trample=Trample+1 WHERE Id = " + id;
                return conn.ExecuteScalar<int>(sql);
            }
        }

        public IEnumerable<PostsModel> GetPostsList()
        {
            using (var conn = SqlHelper.SqlConnection())
            {
                string sql = @"SELECT  * FROM Posts ORDER BY SortCode ASC";
                return conn.Query<PostsModel>(sql);
            }
        }
    }
}